﻿namespace Sample.JQuery {
	using System;
	using System.Web.UI;
	using System.IO;

	public partial class CodePage : Page {

		protected override void OnLoad(System.EventArgs e) {
			base.OnLoad(e);

			string title = Request.QueryString["title"];
			if(!string.IsNullOrEmpty(title)) Title = title;

			string file = Request.QueryString["file"];
			if(string.IsNullOrEmpty(file) || file.Contains("/") || file.Contains("\\")) return;

			string url = "~/" + file + ".aspx";

			string aspxFile = Server.MapPath(url);
			string csFile = aspxFile + ".cs";

			bool aspxFileExists = File.Exists(aspxFile);
			AspxHeader.Visible = aspxFileExists;
			AspxCode.Visible = aspxFileExists;
			if(aspxFileExists) {
				DemoLink.NavigateUrl = url;
				AspxHeader.InnerText = file + ".aspx";
				AspxCode.InnerText = File.ReadAllText(aspxFile);
			}

			bool csFileExists = File.Exists(csFile);
			CsHeader.Visible = csFileExists;
			CsCode.Visible = csFileExists;
			if(csFileExists) {
				CsHeader.InnerText = file + ".aspx.cs";
				CsCode.InnerText = File.ReadAllText(csFile);
			}
		}

	}

}